package com.ars.main;

import com.ars.other.LogOff;
import com.ars.personalInfomation.UpdateName;
import com.ars.personalInfomation.UpdatePassword;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.control.Menu;
import javafx.scene.layout.AnchorPane;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;


public class MainPaneController implements Initializable {

    @FXML
    public AnchorPane mainPane;
    @FXML
    private Menu menuAdministrators;

    //1.航班管理
    @FXML
    public void addPlanAction() {
        changeMainPane("../flight/AddPlane.fxml");
    }

    @FXML
    public void addFlightAction() {
        changeMainPane("../flight/AddFlight.fxml");
    }

    @FXML
    public void addScheduleAction() {
        changeMainPane("../flight/AddSchedule.fxml");
    }

    @FXML
    public void showFlightAction() {
        changeMainPane("../flight/ShowFlight.fxml");
    }

    @FXML
    public void DeleteFlightAction() {
        changeMainPane("../flight/DeleteFlight.fxml");
    }

    // 2.网点管理
    @FXML
    public void addWebsiteAction() {
        changeMainPane("../website/AddWebsite.fxml");
    }

    @FXML
    public void deleteWebsitAction() {
        changeMainPane("../website/DeleteWebsite.fxml");
    }

    @FXML
    public void showWebsitAction() {
        changeMainPane("../website/ShowWebsite.fxml");
    }

    @FXML
    public void showAllList() {
        changeMainPane("../listStatistics/ShowAllList.fxml");
    }

    @FXML
    public void showWebsitList() {
        changeMainPane("../listStatistics/ShowWebsiteList.fxml");
    }

    @FXML
    public void statistlcsWebsitResult() {
        changeMainPane("../listStatistics/WebsiteResultsStatisticsPane.fxml");
    }

    //4.个人信息管理
    @FXML
    public void uptatePasswordAction() {
        new UpdatePassword().show();
    }

    @FXML
    public void updateNameAction() {
        new UpdateName().show();
    }

    //5.管理员管理
    @FXML
    public void addAdministratorsAction() {
        changeMainPane("../administrators/AddAdministrators.fxml");
    }

    @FXML
    public void deleteAdministratorsAction() {
        changeMainPane("../administrators/DeleteAdministrators.fxml");
    }

    //6.其他
    @FXML
    public void exitSystem() {
        new LogOff().Show();
    }

    //切换主面板内容
    private void changeMainPane(String fxmlName) {
        mainPane.getChildren().clear();
        Parent root = null;
        try {
            root = FXMLLoader.load(getClass().getResource(fxmlName));
        } catch (IOException e) {
            e.printStackTrace();
        }
        mainPane.getChildren().add(root);
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        if (User.getLimit() == 2) {
            menuAdministrators.setVisible(false);
        }
    }


}
